package cn.mymall.web.controller.houtai.mall;

import cn.mymall.entity.mall.ShippingTemplate;
import cn.mymall.service.mall.IShippingTemplateService;
import cn.mymall.support.ResultCode;
import cn.mymall.util.BaseWebUtil;
import cn.mymall.util.BindUtils;
import cn.mymall.util.DateUtil;
import cn.mymall.web.controller.houtai.BaseHoutaiController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class ShppingTemplateApiController extends BaseHoutaiController {
    @Autowired
    private IShippingTemplateService shippingTemplateService;


    @RequestMapping("/api/shppingtemplate/list")
    public ResultCode shippingTemplateList() {
        List<ShippingTemplate> list = shippingTemplateService.list(new QueryWrapper<ShippingTemplate>().orderByDesc("id"));
        Map map = new HashMap();
        map.put("shippingTemplateList", list);
        return ResultCode.getSuccessReturn(map);
    }

    @RequestMapping("/api/shppingtemplate/get")
    public ResultCode modifySubcategory(Integer id, Integer categoryId) {
        ShippingTemplate obj = new ShippingTemplate();
        if (id != null) {
            obj = shippingTemplateService.getById(id);
        }
        return ResultCode.getSuccessReturn(obj);
    }

    @RequestMapping("/api/shppingtemplate/save")
    public ResultCode saveSubcategory(Integer id, Integer categoryId) {
        ShippingTemplate obj = null;
        if (id != null) {
            obj = shippingTemplateService.getById(id);
        } else {
            obj = new ShippingTemplate();
            obj.setAddTime(DateUtil.getCurFullTimestamp());
        }

        BindUtils.bindData(obj, BaseWebUtil.getRequestParams());
        shippingTemplateService.saveOrUpdate(obj);
        return ResultCode.SUCCESS;
    }

}
